using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using sbMembership.Library.Presenters;

namespace Tests.sbMembership.AssignRolesToUser
{
    [TestFixture]
    public class AssignRolesToUserTest
    {
        private MockAssignRolesToUserView mockView;
        private AssignRolesToUserPresenter presenter;
        private bool assignRolesToUserCompleteEventRaised;

        [TestFixtureSetUp]
        public void Setup()
        {
            mockView = new MockAssignRolesToUserView();
            presenter = new AssignRolesToUserPresenter(mockView);
            mockView.AttachPresenter(presenter);
        }

        [Test]
        public void InitView()
        {
            presenter.InitViewFor(TestSetup.testUserName);
            Assert.IsNotEmpty(mockView.AvailableRoles);
            Assert.IsNotEmpty(mockView.Message);
        }

        [Test]
        public void AssignRolesToUser()
        {
            mockView.UserToAssign = TestSetup.testUserName;
            presenter.AssignRoleCompleteEvent= new EventHandler(OnAssignRolesToUserCompleteEvent);
            presenter.AssignRole(TestSetup.testRoleName);
            Assert.IsTrue(assignRolesToUserCompleteEventRaised);
        }

        void OnAssignRolesToUserCompleteEvent(object sender, EventArgs e)
        {
            assignRolesToUserCompleteEventRaised = true;
        }
    }
}
